home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / communic / globlwin.zip / DOCGLBLS.WIN
Text File  |  1991-05-22  |  7KB  |  225 lines

  1. "
  2.  
  3. Document your globals, SHOPTALK newsletter Mar/Apr issue.  -- /V Windows version --
  4. Copyright 1991 Shoptalk Systems
  5.  
  6. This file may be distributed freely provided to charge is made except 
  7. for the cost of media and/or transportation.
  8.  
  9. To install this into your Smalltalk/V Windows
  10. image, evaluate the following expression:
  11.  
  12.         | drive |
  13.         drive := Prompter prompt: 'Enter drive letter to read' default: (String with: Disk drive).
  14.         (File pathName: drive, ':docglbls.win') fileIn
  15. "
  16.  
  17.  
  18. Smalltalk at: #BaseKeys put: Dictionary new ;
  19.     at: #Username put: (Prompter prompt: 'What is your name?' default: 'noname') .
  20. Smalltalk keys asSortedCollection do: [ :each | BaseKeys at: each put: 'base' ] !
  21.  
  22.  
  23. DictionaryInspector subclass: #SmalltalkInspector
  24.   instanceVariableNames: ''
  25.   classVariableNames: ''
  26.   poolDictionaries: '' !
  27.                 
  28. !SmalltalkInspector class methods ! !
  29.  
  30. !SmalltalkInspector methods !
  31.  
  32. comment
  33.         "Private - Answer the comment that is associated
  34.          with the selected key."
  35.     instIndex isNil
  36.         ifTrue: [^String new].
  37.     ^(BaseKeys at: (instList at: instIndex) key)!
  38.  
  39. comment: textPane
  40.         "Private - Answer the comment that is associated
  41.          with the selected key."
  42.     instIndex isNil
  43.         ifTrue: [^String new].
  44.     ^textPane contents: (BaseKeys at: (instList at: instIndex) key)!
  45.  
  46. comment: aString from: aDispatcher
  47.         "Private - Compile and evaluate aString.  Replace
  48.          the selected instance variable with the result
  49.          of the evaluation.  Answer true if there is no
  50.          compilation error, else notify aDispatcher as
  51.          to the error and answer false."
  52.     | result |
  53.     instIndex isNil
  54.         ifTrue: [^false].
  55.     BaseKeys
  56.         at: (instList at: instIndex) key
  57.         put: aString.
  58.     self changed: #instance.
  59.     ^true!
  60.  
  61. commentFrom: textPane
  62.         "Private - Compile and evaluate aString.  Replace
  63.          the selected instance variable with the result
  64.          of the evaluation.  Answer true if there is no
  65.          compilation error, else notify aDispatcher as
  66.          to the error and answer false."
  67.     | result aString |
  68.     aString := textPane contents.
  69.     instIndex isNil
  70.         ifTrue: [^false].
  71.     BaseKeys
  72.         at: (instList at: instIndex) key
  73.         put: aString.
  74.     self changed: #instance.
  75.     textPane modified: false.
  76.     ^true!
  77.  
  78. inspectMenu
  79.         "Private - Answer the dictionary
  80.          inspector list pane menu."
  81.     ^Menu
  82.         labels: 'remove\inspect\add\print' withCrs
  83.         lines: Array new
  84.         selectors: #(remove inspectSelection add print)!
  85.  
  86. instVarList
  87.         "Private - Answer an OrderedCollection of
  88.          key strings for the list pane."
  89.     ^instList
  90.         inject: OrderedCollection new
  91.         into: [ :list :assoc |
  92.             (BaseKeys at: assoc key) = 'base'
  93.             ifTrue: [ list add: ' ', assoc value ]
  94.             ifFalse: [ list add: '*', assoc value ].
  95.             list
  96.         ]!
  97.  
  98. instVarList: pane
  99.         "Private - Answer an OrderedCollection of
  100.          key strings for the list pane."
  101.     pane contents: (instList
  102.         inject: OrderedCollection new
  103.         into: [ :list :assoc |
  104.             (BaseKeys at: assoc key) = 'base'
  105.             ifTrue: [ list add: ' ', assoc value ]
  106.             ifFalse: [ list add: '*', assoc value ].
  107.             list
  108.         ])!
  109.  
  110. openOn: anObject
  111.         "Open an inspector window on anObject.  Define
  112.          the pane sizes and behavior, and shedule the
  113.          window."
  114.     | commentPane |
  115.     object := anObject.
  116.     instPane := TextPane new
  117.         owner: self;
  118.         when: #getContents perform: #instance:;
  119.         when: #save perform: #accept:;
  120.         framingRatio: ((1/3) @ 0
  121.             extent: (2/3) @ (4/5)).
  122.     commentPane := TextPane new
  123.         model: self;
  124.         when: #getContents perform: #comment:;
  125.         when: #save perform: #commentFrom:;
  126.         "change: #comment:from:; "
  127.         framingRatio: (0 @ (4/5)
  128.             extent: 1 @ (1/5)).
  129.     self
  130.         label: 'Smalltalk SystemDictionary' ;
  131.         owner: self.
  132.     self addSubpane:
  133.         (ListPane new
  134.             when: #getMenu perform: #inspectMenu:;
  135.             model: self;
  136.             when: #getContents perform: #instVarList:;
  137.             when: #select perform: #selectInstance:;
  138.             when: #doubleClickSelect perform: #inspectSelection:;
  139.             framingRatio: (
  140.                 0@0 extent: (1/3) @ (4/5))).
  141.     self addSubpane: instPane.
  142.     self addSubpane: commentPane.
  143.     self setInstList.
  144.     self openWindow!
  145.  
  146. print
  147.         "send a summary to the printer of BaseKeys values that
  148.          contain comments. cg"
  149.     | pStream |
  150.     pStream := WriteStream on: String new.
  151.     pStream nextPutAll: 'Globals Summary, ', Date today printString.
  152.     pStream cr ; cr.
  153.     BaseKeys keys asSortedCollection do: [ :each |
  154.         (BaseKeys at: each) <> 'base'
  155.         ifTrue: [
  156.             pStream nextPutAll: each ; cr ;
  157.                     nextPutAll: (BaseKeys at: each) ; cr ; cr
  158.         ]
  159.     ].
  160.     pStream contents outputToPrinter!
  161.  
  162. remove
  163.         "Private - Remove the selected
  164.          key from the dictionary."
  165.     | assoc |
  166.     instIndex isNil
  167.         ifFalse: [
  168.             assoc := instList at: instIndex.
  169.             instList remove: assoc.
  170.             object removeKey: assoc key.
  171.             BaseKeys removeKey: assoc key.
  172.             instIndex := nil.
  173.             self
  174.                 changed: #instVarList with: #restore;
  175.                 changed: #instance;
  176.                 changed: #comment
  177.         ]!
  178.  
  179. selectInstance: aListPane
  180.         "Private - Select the instance variable at
  181.          index position anInteger in the list."
  182.     instIndex := aListPane selection.
  183.     self enableInspectItem.
  184.     self changed: #instance:.
  185.     self changed: #comment:! !
  186.  
  187.  
  188. !SystemDictionary methods !
  189.  
  190. add: anAssociation
  191.         "Answer anAssociation.  Add anAssociation to
  192.          receiver dictionary.  Ensure that the key
  193.          is a symbol."
  194.     | stream result |
  195.     Symbol mustBeSymbol: anAssociation key.
  196.     ((self includesKey: anAssociation key) not and: [ self == Smalltalk ])
  197.     ifTrue: [
  198.         stream := WriteStream on: String new.
  199.         stream nextPutAll: Username, ' '.
  200.         Date today printOn: stream.
  201.         stream nextPutAll: ', '.
  202.         Time now printOn: stream.
  203.         stream nextPutAll: ': '.
  204.         result := Prompter
  205.             prompt: 'Enter a description for this new global variable: ', anAssociation key
  206.             default: ''.
  207.         BaseKeys at: anAssociation key put: (stream contents, result)
  208.     ].
  209.     ^super add: anAssociation !
  210.  
  211.  
  212. inspect
  213.         "Open an inspector window on the receiver."
  214.     SmalltalkInspector new openOn: self! !
  215.  
  216.  
  217.  
  218. BaseKeys at: #BaseKeys put: 'Document me' !
  219. BaseKeys at: #SmalltalkInspector put: 'Document me' !
  220. BaseKeys at: #Username put: 'Document me' !
  221.  
  222.  
  223.  
  224.  
  225.